package com.nuanshui.heatedloan.util;

import java.io.PrintWriter;
import java.io.StringWriter;

public class Exceptions {

	public Exceptions() {
	}

	public static RuntimeException unchecked(final Exception e) {
		if (e instanceof RuntimeException)
			return (RuntimeException) e;
		else
			return new RuntimeException(e);
	}

	public static String getStackTraceAsString(final Exception e) {
		final StringWriter stringWriter = new StringWriter();
		e.printStackTrace(new PrintWriter(stringWriter));
		return stringWriter.toString();
	}

	public static boolean isCausedBy(final Exception ex,
			final Class causeExceptionClasses[]) {
		for (Throwable cause = ex.getCause(); cause != null; cause = cause
				.getCause()) {
			final Class arr$[] = causeExceptionClasses;
			final int len$ = arr$.length;
			for (int i$ = 0; i$ < len$; i$++) {
				final Class causeClass = arr$[i$];
				if (causeClass.isInstance(cause))
					return true;
			}

		}

		return false;
	}
}
